package leetcode.median;

import java.util.Arrays;

/**
 * ClassName: $279_NumSquares
 * Description:
 * date: 2022-01-27 19:32
 *
 * @author liyifan
 */
public class $279_NumSquares {
    public int numSquares(int n) {
        int[] dp = new int[n + 1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for (int i = 1;i <= Math.sqrt(n);i++) {
            for (int j = 0;j <= n;j++) {
                if (j >= i * i)
                    dp[j] = Math.min(dp[j], dp[j - i * i] + 1);
            }
        }
        return dp[n];
    }
}
